<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%
	request.setCharacterEncoding("UTF-8");
	response.setContentType("text/html;charset=UTF-8");
%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%
	String path = request.getContextPath();
%>
<html>
<head>
	    <meta charset="utf-8" />
		<title>car2go送车上门</title>
		<meta name="viewport" content="width=device-width,initial-scale=1, maximum-scale=1.0, user-scalable=no" />
		<script>
			var _hmt = _hmt || [];
			(function() {
			  var hm = document.createElement("script");
			  hm.src = "https://hm.baidu.com/hm.js?00c669a13632b889c7e68663fadb613e";
			  var s = document.getElementsByTagName("script")[0]; 
			  s.parentNode.insertBefore(hm, s);
			})();
		</script>
		<link rel="stylesheet" href="<%=path%>/css/reservation/public.css" />	
		<link rel="stylesheet" href="<%=path%>/css/reservation/font-awesome.css" />	
		<script type="text/javascript" src="<%=path%>/js/reservation/jquery-2.2.3.min.js" ></script>
		<script src="<%=path%>/js/reservation/mobiscroll.core.js"></script>
		<script src="<%=path%>/js/reservation/mobiscroll.widget.js"></script>
		<script src="<%=path%>/js/reservation/mobiscroll.scroller.js"></script>
		
		
		<script src="<%=path%>/js/reservation/mobiscroll.util.datetime.js"></script>
		<script src="<%=path%>/js/reservation/mobiscroll.datetimebase.js"></script>
		
		<script src="<%=path%>/js/reservation/mobiscroll.widget.ios.js"></script>
		
		<script src="<%=path%>/js/reservation/mobiscroll.i18n.zh.js"></script>
		<link href="<%=path%>/css/reservation/mobiscroll.animation.css" rel="stylesheet" type="text/css" />
		<link href="<%=path%>/css/reservation/mobiscroll.widget.css" rel="stylesheet" type="text/css" />
		<link href="<%=path%>/css/reservation/mobiscroll.widget.ios.css" rel="stylesheet" type="text/css" />
		<link href="<%=path%>/css/reservation/mobiscroll.scroller.css" rel="stylesheet" type="text/css" />
		<link href="<%=path%>/css/reservation/mobiscroll.scroller.ios.css" rel="stylesheet" type="text/css" />
		<%-- <script src="<%=path%>/js/reservation/maplocation.js" type="text/javascript"></script> --%>
		<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=BDa1313adadf242a075f382451611207"></script>
		<script type="text/javascript">
	        $(function () {
	        	var datenow = '${datenow}';
	        	var stepMinute=10;
	        	var nowDate=new Date(datenow);
	        	if(nowDate.getMinutes()%10!=0){
	        		nowDate.setMinutes(nowDate.getMinutes()+60+(10-nowDate.getMinutes()%10));
	        	}
				var opt= { 
					theme:'ios', //设置显示主题 
					mode:'scroller', //设置日期选择方式，这里用滚动
					display:'bottom', //设置控件出现方式及样式
					preset : 'datetime', //日期:年 月 日 时 分
					minDate: nowDate, 
					maxDate:new Date(nowDate.getFullYear(),nowDate.getMonth(),nowDate.getDate()+2,23,59),
			//              dateFormat: 'yy-mm-dd', // 日期格式
			//              dateOrder: 'yymmdd', //面板中日期排列格式
					stepMinute: stepMinute, //设置分钟步长
					yearText:'年', 
					monthText:'月',
					dayText:'日',
					hourText:'时',
					minuteText:'分',
					lang:'zh' //设置控件语言};
	        };
	        $('#dateinput').mobiscroll(opt);
			/* getBDLocation(); */
	        });
        </script>
</head>
<body>
	<body class="">
	
		<div class="bd">
		<form id="forms" action="<%=path%>/resercus/yuyue.html" method="post">
			<div class='input-bg' style="margin-top: 50%;">
				<input id="user" name="name" type="text" placeholder="姓名"/>
				<input id="rOpenid" name="rOpenid" type="hidden" value="${openid }"/>
				<input id="lng" name="adrLongitude" type="hidden" value=""/>
				<input id="lat" name="adrLatitude" type="hidden" value=""/>
				<input id="" name="spread" type="hidden" value="${spread }"/>
			</div>
			<div class='input-bg'>
				<input id="phone" name="phone" type="text" placeholder="会员注册手机，无须+86"/>
			</div>
			<div class='input-bg'>				
				<input type="text" name="stime" id="dateinput" placeholder="送车时间"/>
				<span class="fa fa-caret-down icon-wz" aria-hidden="true" ></span>
			</div>
			<div class='input-bg'>
				<select name="area" id="area" class="select-x">
					<option value="">请选择送车城区</option>
					<option value="渝中区">渝中区</option>
					<option value="江北区">江北区</option>
					<option value="南岸区">南岸区</option>
					<option value="九龙坡区">九龙坡区</option>
					<option value="沙坪坝区">沙坪坝区</option>
					<option value="大渡口区">大渡口区</option>
					<option value="渝北区">渝北区</option>
					<option value="巴南区">巴南区</option>
					
				</select>
				<span class="fa fa-caret-down icon-wz" aria-hidden="true" ></span>
			</div>
			<div class='input-bg'>
				<input id="address" name="address" type="text" placeholder="送车地点"/>
				<!-- <span class="fa fa-map-marker icon-zb" aria-hidden="true"></span> -->
			</div>
			<div class='input-bg'>
				<input type="text" name="reRemark" placeholder="联系手机：如与注册手机不相同，请填写"/>
			</div>
			<div class="btn-jc">
				<button id="sub_btn" type="button" onclick="sub()" ><img src="../img/reservation/btn.jpg" alt="" /></button>
			</div>
			</form>
		</div>
		<div class="map">
		<span class="dian"><img src="../img/reservation/dian.png" alt="" /></span>
		<div id="map-bd" class="map-bd"></div>
		<div class="map-w">
			<span class="line"></span> <span id="btnOK"
				class="btnqu">确认</span>
		</div>
	</div>
		<script src="<%=path%>/js/layer_mobile/layer.js"></script>
		<script src="http://res.wx.qq.com/open/js/jweixin-1.1.0.js"></script>
		<script type="text/javascript">
			
		</script>
		<script type="text/javascript">
		var spread = '${spread}';
		 var max = '${fn:length(resList)}';
		 var pth = '<%=path%>';
		 var pid = '${pId}';
		 function trim(s){
			    return s.replace(/(^\s*)|(\s*$)/g, "");
			}
		 $('#phone').focus(function(){
			 $(this).val("");
		 });
		 function checkUser(){
			 var tphone = $('#phone').val();
			 if(tphone.indexOf('+86')==-1){
				 tphone="+86"+tphone;
			 }
			 
			 if(tphone.trim() !='' || tphone !=''){
			  $.ajax({  
		    	 type: "post",
	             url:"<%=path%>/resercus/members.html", 
	           	 data: {phone:tphone},
	             dataType: "",
	             async:false,
	             timeout: 1000,  
	             cache: false,  
	             error: phoneerrorFunction,  //错误执行方法    
	             success: phonesuccessFunction //成功执行方法    
	         }); 
			 function phoneerrorFunction(){
				//信息框
				  layer.open({
				    content: '系统忙，请稍后重试'
				    ,btn: '我知道了'
				  });
				  isSecond=false;
			 }
			 function phonesuccessFunction(data){
				 var bl =data;
				 if(bl=="forever"){
					 $('#phone').val('');
					 layer.open({
					    content: 'Sorry，因爽约多次，你已被拉入黑名单。穿上军大衣，自己下楼找车吧！'
					    ,btn: '我知道了'
					  });
					 isSecond=false;
				 }else if(bl=="week"){
					 $('#phone').val('');
					 layer.open({
					    content: 'Sorry，你因爽约2次已经进入黑名单。请7天后再试，下次要按时赴约哦。'
					    ,btn: '下次注意'
					  });
					 isSecond=false;
				 }else if(bl=="true"){
					 layer.closeAll();
					 $("#forms").submit();
				 }else{
					//询问框
						layer.open({
							content: '你竟然还不是car2go会员？'
						    ,btn: ['先去注册', '取消']
						    ,yes: function(index){
						        layer.close(index);
						        window.location.href="https://www.car2go.cn/runr/#/zh/CN/registration/account-personal"; 
						    }
							,no: function(index){
								layer.closeAll();
						        $('#phone').val('');
						        isSecond=false;
						    }
						
						}); 
				 }
			 }
			 }
		 };
		 var isSecond=false;
		 function sub() {
			 if(isSecond){
				 return;
			 }
			 isSecond=true;
	/* 		 $('#phone').trigger("blur"); */
			 //name
			 var name = trim($("#user").val());
			 if(name==''){
				//信息框
				  layer.open({
				    content: '姓名填写有误'
				    ,btn: '我知道了'
				  });
				  isSecond=false;
				  return false; 
			 }
			 //手机号
			 var myreg = /^(((13[0-9]{1})|(14[0-9]{1})|(15[0-9]{1})|(17[0-9]{1})|(18[0-9]{1}))+\d{8})$/;
			 var phone = $("#phone").val();
				if(!myreg.test($("#phone").val())) 
				{ 
			
					//信息框
					  layer.open({
					    content: '手机号填写有误'
					    ,btn: '我知道了'
					  });
					isSecond=false;
				    return false; 
				}
			var stime = trim($("#dateinput").val());
			 if(stime.trim()==''){
				//信息框
				  layer.open({
				    content: '约车时间填写有误'
				    ,btn: '我知道了'
				  });
				  isSecond=false;
				  return false; 
			 }
			 var remark = $("#area").val();
			 if(remark.trim()==''){
					//信息框
					  layer.open({
					    content: '城区选择有误'
					    ,btn: '我知道了'
					  });
					  isSecond=false;
					  return false; 
				 }
			 var address = trim($("#address").val());
			 if(address.trim()==''){
					//信息框
					  layer.open({
					    content: '地址填写有误'
					    ,btn: '我知道了'
					  });
					  isSecond=false;
					  return false; 
				 }
			  layer.open({type: 2}); 
			 //$("#phone").val("+86"+phone);
			 var openid = $('#rOpenid').val();
			 $.ajax({  
		    	 type: "post",
	             url:"<%=path%>/resercus/checkOrder.html", 
	           	 data: {openid:openid,stime:stime},
	             dataType: "",
	             async:false,
	             timeout: 1000,  
	             cache: false,  
	             error: checkOrderErrorFunction,  //错误执行方法    
	             success: checkOrderSuccessFunction //成功执行方法    
	         	});
		 }
		
		 function checkOrderErrorFunction(){
			//信息框
			  layer.open({
			    content: '系统正忙请重试！'
			    ,btn: '我知道了'
			  });
			  isSecond=false;
			  //var remove86Phone=add86Phone.substring(3);
			  //$("#phone").val(remove86Phone);
		 }
		 
		 function checkOrderSuccessFunction(data){
			 if(data=="false"){

				 var timestamp = Date.parse(new Date());

				//信息框
				layer.open({
				    content: '您当前有未完成的订单！'
				    ,btn: '我知道了'
				    ,end: function(index){
						window.location.href='<%=path%>/resercus/ording.html?spread='+spread+'_='+timestamp;
					}    
				});
			 }else if(data=="outTime"){
				//信息框
				layer.open({
				    content: '欢迎预约，我们送车服务将在1月16日零时开始。请留意确认短信哦！'
				    ,btn: '我知道了'
				    ,end: function(index){
	/* 			    	layer.open({type: 2}); */
						 //检测是否黑名单
						 
						 checkUser();
			    	} 
				});
				 
			 }else{
				 //检测是否黑名单
				 checkUser();
			 }
			 //var add86Phone=$("#phone").val();
			 //var remove86Phone=add86Phone.substring(3);
			 //$("#phone").val(remove86Phone);
			
		 }
		
		 function getNowFormatDate(time) {
			    var date = new Date(time);
			    var seperator1 = "-";
			    var seperator2 = ":";
			    var year = date.getFullYear();
			    var month = date.getMonth() + 1;
			    var strDate = date.getDate();
			    if (month >= 1 && month <= 9) {
			        month = "0" + month;
			    }
			    if (strDate >= 0 && strDate <= 9) {
			        strDate = "0" + strDate;
			    }
			    var currentdate = year + seperator1 + month + seperator1 + strDate
			            + " " + date.getHours() + seperator2 + date.getMinutes()
			            + seperator2 + date.getSeconds();
			    return currentdate;
			}
		$('.fs span a').click(function(){
			$('.fs span a').removeClass('a-c');
			$(this).addClass('a-c');
		})
	
		$(document).ready(function(){
				
		});
		
	</script>
		<script type="text/javascript">
	    $('.icon-zb').click(function(){
        	$('.map').show();
        	openMap();
        })
        $('.btnqu').click(function(){
        	$('.map').hide();
        	$("#address").val($(".line").html());
        	$("#lat").val(latitude);
        	$("#lng").val(longitude);
        })
        
        var longitude=0;
	    var latitude=0;
	    
	    function getBDLocation(){
	    	var geoc=new BMap.Geocoder();
	    	var geolocation=new BMap.Geolocation();
	    	geolocation.getCurrentPosition(function(r){
	            if(this.getStatus() == BMAP_STATUS_SUCCESS){
	              	//返回用户位置
	    		    //经度
	    		    longitude=r.point.lng;
	    		    //纬度
	    		    latitude=r.point.lat;
	    		    
	    		    getAddressByPoint(r.point);
	    		    
	            }else {
	                alert('无法定位到您的当前位置，导航失败，请手动输入您的当前位置！'+this.getStatus());
	            }
	        },{enableHighAccuracy: true});
	    }
		
		function openMap(){
			//使用百度地图API
		    //创建地图实例  
		    var map = new BMap.Map("map-bd");
		    //map.disableInertialDragging();
			var geolocationControl = new BMap.GeolocationControl({showAddressBar:false,enableAutoLocation:true});
			geolocationControl.addEventListener("locationSuccess", function(e) {
				getAddressByPoint(e.point);
			});
			map.addControl(geolocationControl);
		    //创建一个坐标
		    var point =new BMap.Point(longitude,latitude);
		    //地图初始化，设置中心点坐标和地图级别  
		    map.centerAndZoom(point,15);
		    
			var dragMapEvent=function(){
	        	var p = map.getCenter();
	        	longitude=p.lng;
				latitude=p.lat;
	        	getAddressByPoint(p);
    		};
			map.addEventListener('dragend', dragMapEvent);
			map.addEventListener("zoomend", dragMapEvent);
		}
		
		function getAddressByPoint(p){
			var geoc=new BMap.Geocoder();
			geoc.getLocation(p, function(rs){
				//alert("sematic_description:"+rs.sematic_description+",pois:"+rs.pois+",business:"+rs.business+", formatted_address:"+rs.formatted_address);
				var addComp = rs.addressComponents;
				var address=addComp.city + addComp.district + addComp.street + addComp.streetNumber;
				$(".line").html(address);
			});
		}
	</script>
		<script type="text/javascript">
		
		//微信jssdk config
		wx.config({
			debug : false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来，若要查看传入的参数，可以在pc端打开，参数信息会通过log打出，仅在pc端时才会打印。
			appId : '${appid}', // 必填，公众号的唯一标识
			timestamp : '${timestamp}', // 必填，生成签名的时间戳
			nonceStr : '${noncestr}', // 必填，生成签名的随机串
			signature : '${signature}',// 必填，签名，见附录1
			jsApiList : [ 'checkJsApi', //判断当前客户端版本是否支持指定JS接口
			'onMenuShareTimeline', //分享给好友
			'onMenuShareAppMessage', //分享到朋友圈
			]
		// 必填，需要使用的JS接口列表，所有JS接口列表见附录2
		});
		wx.ready(function() { //ready函数用于调用API，如果你的网页在加载后就需要自定义分享和回调功能，需要在此调用分享函数。//如果是微信游戏结束后，需要点击按钮触发得到分值后分享，这里就不需要调用API了，可以在按钮上绑定事件直接调用。因此，微信游戏由于大多需要用户先触发获取分值，此处请不要填写如下所示的分享API
					wx.onMenuShareTimeline({ //分享到朋友圈的API  
								title : 'car2go可以送车上门咯！', // 分享标题
								link : 'http://run.xuanzhen-tech.com/car2go_wx/resercus/ording.html?spread='+spread, // 分享链接
								imgUrl : 'http://run.xuanzhen-tech.com/car2go_wx/img/xj.jpg', // 分享图标
								success : function() {
									// 用户确认分享后执行的回调函数
								},
								cancel : function() {
									// 用户取消分享后执行的回调函数
								}
							});
					wx.onMenuShareAppMessage({//分享到朋友 
								title : 'car2go可以送车上门咯！', // 分享标题
								desc : '约吗？钱在这里抢，车在楼下等！', // 分享描述
								link : 'http://run.xuanzhen-tech.com/car2go_wx/resercus/ording.html?spread='+spread, // 分享链接
								imgUrl : 'http://run.xuanzhen-tech.com/car2go_wx/img/xj.jpg', // 分享图标
								type : 'link', // 分享类型,music、video或link，不填默认为link
								dataUrl : '', // 如果type是music或video，则要提供数据链接，默认为空
								success : function() {
									// 用户确认分享后执行的回调函数
								},
								cancel : function() {
									// 用户取消分享后执行的回调函数
								}
							});
				});
		</script>
</body>
</html>